<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        ul{
            display: flex;
        }
        li{
            background-color: aqua;
            color: red;
            padding: 10px 15px;
        }
        li.action{
            background-color: red;
            color: aqua;
        }
        .box{
            position: relative;
        }
        .box > div{
            height: 300px;
            border: 1px solid #000;
            display: none;
        }
        .box > div.action{
            display: block;
        }
    </style>
</head>
<body>
    <ul>
        <li class="action">标题1</li>
        <li>标题2</li>
        <li>标题3</li>
        <li>标题4</li>
    </ul>
    <div class="box">
        <div class="action">内容1111</div>
        <div>内容2222</div>
        <div>内容3333</div>
        <div>内容4444</div>
    </div>
    <script>
        let lis = document.querySelectorAll(`li`);
        let divs = document.querySelectorAll(` .box > div`)
        for (let i = 0; i < lis.length; i++) {
            lis[i].onclick = function () {
                for (var j = 0; j < lis.length; j++) {
                    lis[j].className = ``;
                    divs[j].className = ``;
                }
                this.className = `action`;
                divs[i].className =`action`
                //for (var j = 0; j < length; j++) {
                //    let a = divs[j].classList.contains(`action`);
                //    if (a) {
                //        divs[j].classList.toggle(`action`);
                //    }
                //}
                //divs[i].classList.toggle(`action`);

            }
               
        }
    </script>
</body>
</html>